package com.romain.risotto.entities;

import org.andengine.entity.IEntity;
import org.andengine.entity.modifier.AlphaModifier;
import org.andengine.entity.modifier.IEntityModifier.IEntityModifierListener;
import org.andengine.entity.modifier.ParallelEntityModifier;
import org.andengine.entity.modifier.ScaleModifier;
import org.andengine.entity.sprite.Sprite;
import org.andengine.opengl.vbo.VertexBufferObjectManager;
import org.andengine.util.modifier.IModifier;

import android.util.Log;

import com.romain.risotto.Constantes;
import com.romain.risotto.manager.GameManager;
import com.romain.risotto.texture.Textures;

public class Rocher extends SpaceSpriteObject {

	public Rocher(float pX, float pY, VertexBufferObjectManager vbo) {

		super(false, pX, pY, Textures.textureRoc1, vbo);
		this.setScale(0.2f + (float) Math.random() * .4f);
	}

	@Override
	protected void onManagedUpdate(final float pSecondsElapsed) {

		super.onManagedUpdate(pSecondsElapsed);
		Ship ship = GameManager.getInstance().getMainShip();
		if (!ship.isDead() && this.collidesWith(ship)) {
			ship.explode();
			return;
		}
	}

	public void touch(Bullet bullet) {

		ParallelEntityModifier sm = new ParallelEntityModifier(
				new ScaleModifier(0.6f, 0.2f, 1.7f), new AlphaModifier(1.6f, 1,
						0));
		sm.addModifierListener(new IEntityModifierListener() {
			@Override
			public void onModifierStarted(final IModifier<IEntity> pModifier,
					final IEntity pItem) {
			}

			@Override
			public void onModifierFinished(
					final IModifier<IEntity> pEntityModifier,
					final IEntity pEntity) {
				Rocher.this.delete();
			}
		});

		this.setAlpha(0);
		Log.d("risotto", "explostion de asteroid !");
		Sprite explosionSprite = new Sprite(0, 0, Textures.textureExplosion,
				this.getVertexBufferObject());
		explosionSprite.setScale(0.2f);
		explosionSprite.setPosition(-10, -10);
		explosionSprite.registerEntityModifier(sm);
		this.attachChild(explosionSprite);

	}

	@Override
	protected void createBody() {
		// TODO Auto-generated method stub
		
	}

}
